"""
    列表推导式
"""
list1 = [ x for x in range(30) if x%2==0]
print(list1)

"""
    字典推导式
"""
dict1 = {x:x**2 for x in range(3)}
print(dict1)

list2 = ["abc","abcd","abcd4"]
dict2 = {x:len(x) for x in list2}

print(dict2)

"""
    集合推导式
"""
set1 = {x*x for x in range(1,4)}
print(set1)

"""
    元组推导式
"""
tuple1 = (x for x in range(10) if x%2!=0)
#<class 'generator'>
# 注意此时得到的结果还是个生成器对象
print(type(tuple1))
# 我们需要把生成器对象转元组
true_tuple1 = tuple(tuple1)
#(1, 3, 5, 7, 9)
print(true_tuple1)